package com.lwl.controller.sas;


import com.github.pagehelper.PageInfo;
import com.lwl.entity.*;
import com.lwl.entity.sas.TSasPlane;
import com.lwl.service.sas.TSasPlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("tSasPlane")
public class TSasPlaneController {
    @Autowired
    private TSasPlaneService tSasPlaneService;

    /**
     * 查询所有的测试计划
     * @return
     */
    @GetMapping("queryAll")
    public LayData queryAll(MyPage myPage, TSasPlane tSasPlane){
        PageInfo pageInfo = tSasPlaneService.queryAll(myPage,tSasPlane);
        return new LayData(pageInfo);
    }

    /**
     * 根据邀请码查询对应的测试计划
     * @param tSasPlane
     * @return
     */
    @PostMapping("selectCode")
    public LayData selectCode(TSasPlane tSasPlane){
        boolean status = tSasPlaneService.selectCode(tSasPlane);
        return new LayData(status);
    }

    /**
     *  添加/修改 测试计划
     */
    @PostMapping("addPlane")
    public LayData insertplane(TSasPlane tSasPlane, HttpSession session){
        Tuser user = (Tuser)session.getAttribute("user");
        tSasPlane.setCreatetime(new Date());
        tSasPlane.setUid(user.getId());
        return new LayData(tSasPlaneService.insertPlane(tSasPlane));
    }

    /**
     * 计划唯一性校验
     */
    @PostMapping("queryByPlaneName")
    public LayData queryByName(String planname){
        return  new LayData(tSasPlaneService.queryByName(planname));
    }

    /**
     * 根据邀请码查询测试计划的具体内容
     * @param tSasPlane
     * @return
     */
    @GetMapping("getByCode")
    public LayData getByCode(TSasPlane tSasPlane){
        TSasPlane tSasPlanes = tSasPlaneService.getByCode(tSasPlane);
        return new LayData(tSasPlanes);
    }



}
